package com.spotmanger.project.modular.spottable.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spotmanger.project.common.core.utils.DataResult;
import com.spotmanger.project.modular.spottable.entity.SpottableJsxmEntity;
import com.spotmanger.project.modular.spottable.service.SpottableJsxmNewService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 建设项目图斑信息表。该表中包含建设项目图斑的有关信息，是对基本信息的补充，建设项目图斑应填写该表。
 *
 * @author leihao
 * @email 1321451088@qq.com
 * @date 2021-09-20 10:53:23
 */
@Controller
@RequestMapping("/")
public class SpottableJsxmNewController {
    @Autowired
    private SpottableJsxmNewService spottableJsxmNewService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/spottableJsxmNew")
    public String spottableJsxmNew() {
        return "spottable/spottablejsxmnew/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("spottableJsxmNew/add")
    @RequiresPermissions("spottableJsxmNew:add")
    @ResponseBody
    public DataResult add(@RequestBody SpottableJsxmEntity spottableJsxmNew){
        spottableJsxmNewService.save(spottableJsxmNew);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("spottableJsxmNew/delete")
    @RequiresPermissions("spottableJsxmNew:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        spottableJsxmNewService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("spottableJsxmNew/update")
    @RequiresPermissions("spottableJsxmNew:update")
    @ResponseBody
    public DataResult update(@RequestBody SpottableJsxmEntity spottableJsxmNew){
        spottableJsxmNewService.updateById(spottableJsxmNew);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("spottableJsxmNew/listByPage")
    @RequiresPermissions("spottableJsxmNew:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SpottableJsxmEntity spottableJsxmNew){
        Page page = new Page(spottableJsxmNew.getPage(), spottableJsxmNew.getLimit());
        //通过TBBH字段来实现模糊查询
        LambdaQueryWrapper<SpottableJsxmEntity> queryWrapper = spottableJsxmNewService.searchByTBBH(spottableJsxmNew);
        IPage<SpottableJsxmEntity> iPage = spottableJsxmNewService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
